var redis = require('redis'),
  RDS_PORT = 6379, //端口号  
  RDS_HOST = '139.196.120.190', //服务器IP  要连接的A服务器redis  
  RDS_PWD = 'ww1234567', //密码  
  RDS_OPTS = {}, //设置项  
  client = redis.createClient(RDS_PORT, RDS_HOST, RDS_OPTS);
client.auth(RDS_PWD, function() {
  console.log('通过认证');
});
client.on('connect', function() {
  client.set('author', 'Wilson', redis.print);
  client.get('author', redis.print);
  console.log('connect');
});
client.on('ready', function(err) {
  console.log('ready');
});

client1 = redis.createClient(RDS_PORT, RDS_HOST, RDS_OPTS);
client1.auth(RDS_PWD, function() {
  console.log('通过认证');
});
client1.on('connect', function() {
  client1.set('author1', 'Wilson', redis.print);
  client1.get('author1', redis.print);
  console.log('connect');
});
client1.on('ready', function(err) {
  console.log('ready');
});


client.send_command('config', ['set', 'notify-keyspace-events', 'Ex'], SubscribeExpired);

function SubscribeExpired(e, r) {
  const expired_subKey = '__keyevent@0__:expired';
  client1.subscribe(expired_subKey, function() {

    client1.on('message', function(chan, msg) {
      console.log(chan, msg)
      //msg就是过期的key值，由于过期了，所有回调时只有key值
      //相应的处理代码
    });
  });
}